package com.example.source;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.connector.file.src.FileSource;
import org.apache.flink.connector.file.src.reader.TextLineInputFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * Created with IntelliJ IDEA.
 * ClassName: File
 * Package: com.example.source
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-07-18
 * Time: 13:40
 */

//从文件读取数据
public class FileSourceDemo {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env =
                StreamExecutionEnvironment.getExecutionEnvironment();

        //设置并行度为1
        env.setParallelism(1);

        //从文件读
        FileSource<String> build =
                FileSource.forRecordStreamFormat(new TextLineInputFormat(),
                        new Path("input/word.txt")).build();

        /**
         * 从文件中读 formSource Source实现类 Watermark 名字
         */
        env.fromSource(build, WatermarkStrategy.noWatermarks(),"filesource")
                .print();

        env.execute();
    }
}
